package com.dean.pokeking

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyGridState
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import com.dean.pokeking.ui.pages.MainPage
import com.dean.pokeking.ui.theme.PokekingComposeTheme
import com.dean.pokeking.utils.FileUtil
import java.io.File
import kotlin.random.Random

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        WindowCompat.setDecorFitsSystemWindows(window, false)
        firstRun()
        val currentTeam = getSharedPreferences(MY_SP, 0).getString(CURRENT_TEAM, "小蛋队")!!
        Log.d("test", "read team name success, teamName= $currentTeam")
        setContent {
            MainPage(currentTeam) {
                FileUtil.copyTeamsFolderToPrivateSpace(this)
                Toast.makeText(this, "重置数据成功！", Toast.LENGTH_SHORT).show()
            }
        }
    }

    private fun firstRun() {
        val sharedPreference = getSharedPreferences(MY_SP, 0)
        val firstRun = sharedPreference.getBoolean(FIRST_RUN, true)
        if (firstRun) {
            FileUtil.copyTeamsFolderToPrivateSpace(this)
            sharedPreference.edit().putBoolean(FIRST_RUN, false).apply()
        }
    }

}